//
//  KLineChart.h
//  Stock_Pro
//
//  Created by imuse on 10-12-18.
//  Copyright 2010 gaotime. All rights reserved.
//

#import <UIKit/UIKit.h>

#import "DrawTools.h"
#import "QuoteLvData.h"
#import "QuoteLvKIndex.h"
#import "HZBaseMarketView.h"

#define KVIEW_PRICE_SCALES_NUM	5
#define KVIEW_VOLUME_SCALES_NUM	3

enum KLINE_EX_TYPE_tag {
	KLINE_EX_TYPE_VOL = 0,	//成交量
	KLINE_EX_TYPE_MACD,		//MACD
	KLINE_EX_TYPE_KDJ,		//KDJ
	KLINE_EX_TYPE_RSI,		//RSI
	KLINE_EX_TYPE_WR,		//WR
	KLINE_EX_TYPE_BOLL,		//BOLL
	KLINE_EX_TYPE_BIAS,		//BIAS
	KLINE_EX_TYPE_DMA,		//DMA
	KLINE_EX_TYPE_CCI,		//CCI
	KLINE_EX_TYPE_ARBR,		//ARBR
	KLINE_EX_TYPE_PSY,		//PSY
  KLINE_EX_TYPE_DDX,    //DXX
  KLINE_EX_TYPE_DDY,    //DDY
  KLINE_EX_TYPE_DDZ,    //DDZ
  KLINE_EX_TYPE_BBD_RETAI,    //散户持仓
  KLINE_EX_TYPE_BBD_MAIN,     //主力持仓
  KLINE_EX_TYPE_BBD,          //主力净额
  KLINE_EX_TYPE_AVG_VOL_SUM,  //均量，均额
};
//add by jason
enum KLINE_MODE_tag {
	KLINE_MODE_NORMAL = 0,
	KLINE_MODE_SPECIAL, 
};
//end

enum KSwipeOrientation {
    KSwipe_RIGHT_Orientation = 1,
    KSwipe_Left_Orientation,
};

typedef struct K_POINT_HL_tag {
	int x;
	int yHight;
	int yLow;
}K_POINT_HL;

typedef struct K_POINT_BOLL_tag {
	int x;
	int yHight;
	int yLow;
	int xOpen;
	int	yOpen;
	int xCur;
	int	yCur;
}K_POINT_BOLL;

@protocol KLineChartDelegate <NSObject>

@optional
- (void)movePul:(NSArray*)dataArray withColor:(NSArray*)colorArray;
@end

@interface KLineChart : HZBaseMarketView {
	
	/*k线数据*/
	QUOTELV_K_RES *pKRes;
	
	QUOTELV_K_INDEX *pKIndex;
	
	/*上涨价*/
	GUI_RECT *pRectUp;
	/*下跌价*/
	GUI_RECT *pRectDown;
	/*上涨最高最低*/
	K_POINT_HL *pUp;
	/*下跌最高最低*/
	K_POINT_HL *pDown;
	
	/*上涨个数*/
	int nUpLen;
	/*下跌个数*/
	int nDownLen;
	
	/*均价*/
	GUI_POINT *pLine5;
	GUI_POINT *pLine10;
	GUI_POINT *pLine20;
  GUI_POINT *pLine60;
	
	/*成交量 上涨*/
	GUI_RECT *pRectUpVol;
	/*成交量 下跌*/
	GUI_RECT *pRectDownVol;
	
	/*KDJ K*/
	GUI_POINT *pLineK;
	/*KDJ D*/
	GUI_POINT *pLineD;
	/*KDJ J*/
	GUI_POINT *pLineJ;
	
	/*RSI 6*/
	GUI_POINT *pLineRSI6;
	/*RSI 12*/
	GUI_POINT *pLineRSI12;
	/*RSI 24*/
	GUI_POINT *pLineRSI24;
	
	/*MACD*/
	GUI_POINT *pLineDIF;
	GUI_POINT *pLineDEA;
	GUI_POINT *pLineDDUp;
	GUI_POINT *pLineDDDown;
	int nMACD_Y_0;//macd0轴位置
	int nMACD_DDUpLen;
	int nMACD_DDDownLen;

	float fScalesPrice[KVIEW_PRICE_SCALES_NUM];			//价刻度
	long64 lScalesVolume[KVIEW_VOLUME_SCALES_NUM];		//量刻度
	
	float fScalesRSI[KVIEW_VOLUME_SCALES_NUM];
	float fScalesMACD[KVIEW_VOLUME_SCALES_NUM];
	
	/*WR 14*/
	GUI_POINT *pLineWR1;
	/*WR 28*/
	GUI_POINT *pLineWR2;
	float fScalesWR[KVIEW_VOLUME_SCALES_NUM];
	
	/*BIAS 6*/
	GUI_POINT *pLineBIAS1;
	/*BIAS 12*/
	GUI_POINT *pLineBIAS2;
	/*BIAS 24*/
	GUI_POINT *pLineBIAS3;
	float fScalesBIAS[KVIEW_VOLUME_SCALES_NUM];
	
	/*ARBR AR*/
	GUI_POINT *pLineAR;
	/*ARBR BR*/
	GUI_POINT *pLineBR;
	float fScalesARBR[KVIEW_VOLUME_SCALES_NUM];
	
	/*CCI*/
	GUI_POINT *pLineCCI;
	float fScalesCCI[KVIEW_VOLUME_SCALES_NUM];
	
	/*DMA DDD*/
	GUI_POINT *pLineDDD;
	/*DMA AMA*/
	GUI_POINT *pLineAMA;
	float fScalesDMA[KVIEW_VOLUME_SCALES_NUM];
	
	/*PSY*/
	GUI_POINT *pLinePSY;
	float fScalesPSY[KVIEW_VOLUME_SCALES_NUM];
	
	/*BOLL MID*/
	GUI_POINT *pLineMID;
	/*BOLL UPPER*/
	GUI_POINT *pLineUPPER;
	/*BOLL */
	GUI_POINT *pLineLOWER;
	float fScalesBOLL[KVIEW_VOLUME_SCALES_NUM];
	
	/*BOLL K线上涨*/
	K_POINT_BOLL *pBollUp;
	/*BOLL K线下跌*/
	K_POINT_BOLL *pBollDown;
  
  //lisz add 20110916 start
  GUI_POINT *pDDX1;
  GUI_POINT *pDDX2;
  GUI_POINT *pDDX3;
  int nDDX_Y_0;//ddx 0轴位置
  int nDDX_DDUpLen;
	int nDDX_DDDownLen;
  GUI_RECT *pLineDDXUp;
	GUI_RECT *pLineDDXDown;
  float fScalesDDX[KVIEW_VOLUME_SCALES_NUM];
  //lisz add 20110916 end
  
	/*偏移位置*/
	int nPosStart;
	
	/*k线宽度*/
	int nKLineWidth;
	
	//	/*K线最大个数*/
	//	int nKMaxNum;
	
	/*是否重新计算k线起始位置*/
	BOOL bIsCalcStartPos;
	
	/*十字线位置*/
	int nPos;
	
	/*拖动时候的定时器*/
	NSTimer *pTimer;
		
	/*多点触摸时用到*/
	int nMTWidthOld;
	
	/*放大时的距离*/
	int nMTDistance;
	
	/*扩展线类型，即成交量，MACD, RSI, KDJ*/
	int nLineExType;
	
	/**/
	BOOL bToMovePul;
  
  int nPriceTop;              //价y坐标
	int nVolTop;                //量y坐标
	int nPriceHeight;           //价高
	int nVolHeight;             //量高
    int nMiddleVolTop;          //特殊样式下的量坐标
    int nMiddleVolHeight;       //特殊样式下的量高度
	
	int n_Mode;
	
	//新版
  int bgColor;
	int nM5Color;
	int nM10Color;
	int nM20Color;
  int nM60Color;
	int nTenLineColor;
	int nVolTitleColor;
  int nUpFrameColor;
	int nUpFulllColor;
	int nDownFullColor;
  //边框颜色
  int  frameColor;
  int  scalesLineColor;
    int nIndexsColor; //指标名称
	//
	//
	UIImageView *mLeftView;
	UIImageView *mBottomView;
	UILabel			*mLeft;
	UILabel			*mBottom;
	float				ty;
	float				pMax;
	float				pMin;
	//
	//end
    
  BOOL                isLandscape;           //是否横屏
  BOOL                isShow10Line;          //是否显示十字线
  BOOL                isMoved;               //是否触摸移动
  CGPoint             nSwipeLastPoint;       //左右清扫的上一个点
  NSMutableArray     *pTimeLineArrayM;       //每月时间线集合
  NSMutableArray     *pKLineMiddlePointArray;//K线中间点坐标集合
  
  UIButton    *mVerButton;//换横屏按钮
  UIButton    *mAveButton;//设均线按钮
  UIButton    *mIndexButton;//选指标按钮
  UIButton    *mComplexButton;//复权按钮
  UIButton    *mLeftButton;//换左滑按钮
  UIButton    *mRightButton;//设右滑按钮
  UIButton    *mDownButton;//缩小按钮
  UIButton    *mUpButton;//变大按钮
    UIButton  *pLandScapeBtn;
}

@property(nonatomic, assign) id<KLineChartDelegate> delegate;
@property (nonatomic, assign)BOOL                   isLandscape;

- (id)initWithFrame:(CGRect)frame withParent:(id)parent;

-(void)setData:(QUOTELV_K_RES*)p withIndex:(QUOTELV_K_INDEX*)k;
-(void)calcData;
-(void)clear;

- (int)KLine_DrawMaxNumber;
- (void)addKLineWidth;
- (void)subKLineWidth;

- (void)movePul:(NSTimer*)timer;

-(void)movePos:(int)nIndex;
-(int)getAbsPos;
/*隐藏10字线*/
-(void)hiddedPul;

-(void)drawVol:(CGContextRef)g;
-(void)drawKDJ:(CGContextRef)g withCount:(int)nCount;
-(void)drawRSI:(CGContextRef)g withCount:(int)nCount;
-(void)drawMACD:(CGContextRef)g withCount:(int)nCount;
-(void)drawWR:(CGContextRef)g withCount:(int)nCount;
-(void)drawBIAS:(CGContextRef)g withCount:(int)nCount;
-(void)drawARBR:(CGContextRef)g withCount:(int)nCount;
-(void)drawCCI:(CGContextRef)g withCount:(int)nCount;
-(void)drawDMA:(CGContextRef)g withCount:(int)nCount;
-(void)drawPSY:(CGContextRef)g withCount:(int)nCount;
-(void)drawBOLL:(CGContextRef)g withCount:(int)nCount;
//lisz add 20110916 start
///绘ddx,ddy,ddz
-(void)drawDDX:(CGContextRef)g withCount:(int)nCount;
///绘bbd主力、散户持仓
-(void)drawBBDRetaiMain:(CGContextRef)g withCount:(int)nCount;
///绘bbd净额
-(void)drawBBD:(CGContextRef)g withCount:(int)nCount;
///绘均量均额
-(void)drawAvgVolSum:(CGContextRef)g withCount:(int)nCount;
//lisz add 20110916 end

-(void)setMTDistance:(int)n;
-(void)setLineExType:(int)n;

-(void)setMulDelegate:(id <KLineChartDelegate>)anObject;

-(void)formatShowDate:(int)nDate withDis:(char*)sBuf;

-(void)upMulData;

///切换显示指标
-(void)setCurShowIndex:(int)n;
-(int)getShowIndex;
///add by jason 判断涨跌颜色
-(int)isUpOrDown:(int)nIndex;
-(void)setMode:(int)nMode;
//end
-(void)setColors:(NSArray*)aArray;
-(void)OnChangeView:(int)n;

//设置附图指标
- (void)setSubChartIndex:(NSInteger)tag;
/**
 * 获取十字线状态
 */
- (BOOL)getTenLineStat;
/**
 * 设置十字线状态
 */
- (void)setTenLineState:(BOOL)isHidden;

- (void)setCalcStartPos:(BOOL)bStartPos;
- (void)OnChangeTheme:(int)nThemeId withPath:(NSString*)path;
- (void)changeIndex:(NSString *)indexName;
- (void)setLandScapeBtnHidden:(BOOL)hidden;

- (void)updateNewData;
@end
